package com.jaya.budan.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jaya.budan.R;
import com.jaya.budan.activity.My_Wallet_Recharge_Activity;
import com.jaya.budan.activity.Square_Detail_Activity;
import com.jaya.budan.activity.Square_Detail_Photo_Activity;
import com.jaya.budan.activity.TaRen_Main_Activity;
import com.jaya.budan.bean.ListUser_Information;
import com.jaya.budan.bean.User_Limit;
import com.jaya.budan.bean.User_Wallet;
import com.jaya.budan.connect.RequestConnect;
import com.jaya.budan.utils.ToolUtils;
import com.jaya.budan.utils.VolleyUtil;
import com.jaya.budan.views.Circle_ImageView;
import com.jaya.budan.views.CommentExpandableListView;
import com.jaya.budan.views.CommonPopWindow;
import com.jaya.budan.views.CustomListView;
import com.jaya.budan.views.HorizontalListView;
import com.jaya.budan.views.MyGridView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.List;

public class LV_DongtaiTG_Adapter extends BaseAdapter{

    private Context mcontext;
    private List<ListUser_Information> mlist;
    private List<User_Wallet> mlist_wallet;
    private String access_token, bd_money, s_id, type;
    private int mtype;

    public LV_DongtaiTG_Adapter(Context context, List<ListUser_Information> list, int type, String token){
        mcontext = context;
        mlist = list;
        mtype = type;
        access_token = token;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (mtype == 0){
            convertView = View.inflate(mcontext, R.layout.lv_dongtaitg_item, null);
            TextView tv_dongtaitg_name = convertView.findViewById(R.id.tv_dongtaitg_name);
            TextView tv_dongtaitg_create = convertView.findViewById(R.id.tv_dongtaitg_create);
            TextView tv_dongtaitg_item_remark = convertView.findViewById(R.id.tv_dongtaitg_item_remark);
            ImageView iv_dongtaitg_icon = convertView.findViewById(R.id.iv_dongtaitg_icon);
            tv_dongtaitg_name.setText("" + mlist.get(position).getNicename());
            tv_dongtaitg_create.setText("" + mlist.get(position).getCreate_at());
            tv_dongtaitg_item_remark.setText("" + mlist.get(position).getContent());
            Glide.with(mcontext).load(mlist.get(position).getHead_path() + "").apply(new RequestOptions()
                    .placeholder(R.mipmap.bd_circle_logo).error(R.mipmap.bd_circle_logo)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_dongtaitg_icon);
        } else if (mtype == 2){
            convertView = View.inflate(mcontext, R.layout.square_frag_listview_item, null);
            Circle_ImageView iv_nearby_item_icon = convertView.findViewById(R.id.iv_nearby_item_icon);
            ImageView iv_nearby_item_isvip = convertView.findViewById(R.id.iv_nearby_item_isvip);
            ImageView iv_square_dianzan = convertView.findViewById(R.id.iv_square_dianzan);
            ImageView iv_square_diandian = convertView.findViewById(R.id.iv_square_diandian);
            ImageView iv_square_care = convertView.findViewById(R.id.iv_square_care);
            HorizontalListView main_hlv_vip = convertView.findViewById(R.id.main_hlv_vip);
            LinearLayout ll_square_dianzan = convertView.findViewById(R.id.ll_square_dianzan);
            LinearLayout ll_square_pinglun = convertView.findViewById(R.id.ll_square_pinglun);
            TextView tv_nearby_listview_item_name = convertView.findViewById(R.id.tv_nearby_listview_item_name);
            TextView tv_nearby_listview_item_distance = convertView.findViewById(R.id.tv_nearby_listview_item_distance);
            TextView tv_nearby_listview_item_content = convertView.findViewById(R.id.tv_nearby_listview_item_content);
            TextView tv_nearby_listview_item_look = convertView.findViewById(R.id.tv_nearby_listview_item_look);
            TextView tv_geren_main_dianzan = convertView.findViewById(R.id.tv_geren_main_dianzan);
            TextView tv_geren_main_pinglun = convertView.findViewById(R.id.tv_geren_main_pinglun);
            TextView tv_geren_main_zhichi = convertView.findViewById(R.id.tv_geren_main_zhichi);
            MyGridView gv_square_nearby = convertView.findViewById(R.id.gv_square_nearby);
            tv_nearby_listview_item_name.setText("" + mlist.get(position).getNicename());
            tv_nearby_listview_item_distance.setText("" + mlist.get(position).getDistance() + " | " + mlist.get(position).getCreate_at());
            tv_nearby_listview_item_content.setText("" + mlist.get(position).getContent());
            if (ToolUtils.isEmpty(mlist.get(position).getAddress())){
                tv_nearby_listview_item_look.setVisibility(View.GONE);
            } else {
                tv_nearby_listview_item_look.setVisibility(View.VISIBLE);
                tv_nearby_listview_item_look.setText("" + mlist.get(position).getAddress());
            }
            tv_geren_main_dianzan.setText("" + mlist.get(position).getComment_count());
            tv_geren_main_dianzan.setSelected(true);
            tv_geren_main_pinglun.setText("" + mlist.get(position).getShare());
//            mlist.get(position).getFiles().get(position).getPath();
            Glide.with(mcontext).load(mlist.get(position).getHead_path() + "").apply(new RequestOptions()
                    .placeholder(R.mipmap.bd_circle_logo).error(R.mipmap.bd_circle_logo)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_nearby_item_icon);
            gv_square_nearby.setHorizontalSpacing(15);
            gv_square_nearby.setVerticalSpacing(15);
            gv_square_nearby.setAdapter(new Photo_Album_Adapter(mcontext, null, mlist.get(position).getFiles(), null, 1));
            gv_square_nearby.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    //图片放大
                    Intent intent = new Intent(mcontext, Square_Detail_Photo_Activity.class);
                    intent.putExtra("access_token", access_token);
                    intent.putExtra("roomId", position);
                    intent.putExtra("user_information", (Serializable) mlist);
                    mcontext.startActivity(intent);
//                    CommonPopWindow.newBuilder()
//                            .setView(R.layout.pop_square_detail)
//                            .setAnimationStyle(R.style.AnimUp)
//                            .setBackgroundDrawable(new BitmapDrawable())
//                            .setSize(0, 1800)
//                            .setViewOnClickListener(new CommonPopWindow.ViewClickListener() {
//                                @Override
//                                public void getChildView(PopupWindow mPopupWindow, View view, int mLayoutResId) {
//                                    ViewPager pop_vp_square_detail = view.findViewById(R.id.pop_vp_square_detail);
//                                    TextView tv_pop_square_detail = view.findViewById(R.id.tv_pop_square_detail);
//                                    ImageView iv_pop_square_detail = view.findViewById(R.id.iv_pop_square_detail);
//                                    pop_vp_square_detail.setAdapter(new Square_ViewPagerAdapter(mcontext, mlist.get(selected).getFiles()));
//                                    pop_vp_square_detail.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//                                        @Override
//                                        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//                                            int count = position + 1;
//                                            tv_pop_square_detail.setText(count + "/" + mlist.get(selected).getFiles().size());
//                                        }
//
//                                        @Override
//                                        public void onPageSelected(int position) {
//                                            Log.d("square_square", position + "");
//                                        }
//
//                                        @Override
//                                        public void onPageScrollStateChanged(int state) {
//                                            Log.d("square_square", state + "");
//                                        }
//                                    });
//                                    iv_pop_square_detail.setOnClickListener(new View.OnClickListener() {
//                                        @Override
//                                        public void onClick(View v) {
//                                            mPopupWindow.dismiss();
//                                        }
//                                    });
//                                }
//                            })
//                            .setBackgroundDarkEnable(true)
//                            .setOutsideTouchable(false)
//                            .setBackgroundAlpha(0.0f)
//                            .build(mcontext)
//                            .showAsCenter(view);
                }
            });
            ll_square_dianzan.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (tv_geren_main_dianzan.isSelected()){
                        tv_geren_main_dianzan.setSelected(false);
                        type = "1";
                        iv_square_dianzan.setImageResource(R.mipmap.iv_dianzan_yes);
                    } else {
                        tv_geren_main_dianzan.setSelected(true);
                        type = "2";
                        iv_square_dianzan.setImageResource(R.mipmap.iv_dianzan_no);
                    }
                    JSONObject object = new JSONObject();
                    try {
                        object.put("type", type);//1点赞 2取消点赞
                        object.put("s_id", mlist.get(position).getFiles().get(0).getS_id());
                        object.put("s_com_id", "");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    postData(object, tv_geren_main_dianzan);
                }
            });
            tv_geren_main_zhichi.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   postZhiChiData(v, position);
                }
            });
            iv_nearby_item_icon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mcontext, TaRen_Main_Activity.class);
                    intent.putExtra("access_token", access_token);
                    intent.putExtra("roomId", position + "");
                    intent.putExtra("uid", mlist.get(position).getUid());
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mcontext.startActivity(intent);
                }
            });
            iv_square_diandian.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CommonPopWindow.newBuilder()
                            .setView(R.layout.pop_geren_diandian)
                            .setAnimationStyle(R.style.AnimUp)
                            .setBackgroundDrawable(new BitmapDrawable())
                            .setSize(0, 400)
                            .setViewOnClickListener(new CommonPopWindow.ViewClickListener() {
                                @Override
                                public void getChildView(PopupWindow mPopupWindow, View view, int mLayoutResId) {
                                    TextView tv_pop_diandian_cancle = view.findViewById(R.id.tv_pop_diandian_cancle);
                                    tv_pop_diandian_cancle.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            mPopupWindow.dismiss();
                                        }
                                    });
                                }
                            })
                            .setBackgroundDarkEnable(true)
                            .setOutsideTouchable(false)
                            .setBackgroundAlpha(0.7f)
                            .build(mcontext)
                            .showAsBottom(v);
                }
            });
            iv_square_care.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    JSONObject object = new JSONObject();
                    try {
                        object.put("uid", mlist.get(position).getUid());
                        object.put("type", 1);//1 关注 2取消关注
                        object.put("flag", 1);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    postUserFansData(object, iv_square_care);
                }
            });
            ll_square_pinglun.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mcontext, Square_Detail_Activity.class);
                    intent.putExtra("access_token", access_token);
                    intent.putExtra("roomId", position);
                    intent.putExtra("user_information", (Serializable) mlist);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mcontext.startActivity(intent);
                }
            });
//            if (mlist.get(position).getIs_vip() == 1){
//                iv_nearby_item_isvip.setVisibility(View.VISIBLE);//是 会员
//            } else {
//                iv_nearby_item_isvip.setVisibility(View.INVISIBLE);
//            }
            // 获取屏幕宽高
//            int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // 屏幕宽（像素，如：480px）
//            HorizontalListViewAdapter horizontalListViewAdapter = new HorizontalListViewAdapter(mcontext, screenWidth, mlist);
//            main_hlv_vip.setAdapter(horizontalListViewAdapter);
        } else {
            convertView = View.inflate(mcontext, R.layout.geren_main_listview_item, null);
            Circle_ImageView iv_nearby_item_icon = convertView.findViewById(R.id.iv_nearby_item_icon);
            ImageView iv_geren_main_banner = convertView.findViewById(R.id.iv_geren_main_banner);
            TextView tv_nearby_listview_item_name = convertView.findViewById(R.id.tv_nearby_listview_item_name);
            TextView tv_nearby_listview_item_distance = convertView.findViewById(R.id.tv_nearby_listview_item_distance);
            TextView tv_nearby_listview_item_content = convertView.findViewById(R.id.tv_nearby_listview_item_content);
            TextView tv_nearby_listview_item_look = convertView.findViewById(R.id.tv_nearby_listview_item_look);
            TextView tv_geren_main_dianzan = convertView.findViewById(R.id.tv_geren_main_dianzan);
            TextView tv_geren_main_pinglun = convertView.findViewById(R.id.tv_geren_main_pinglun);
            TextView tv_geren_main_open_all = convertView.findViewById(R.id.tv_geren_main_open_all);
            CustomListView lv_xyf_jilu = convertView.findViewById(R.id.lv_xyf_jilu);
            if (mlist.get(position).getFiles() != null){
                Log.d("dongtai", mlist.get(position).getFiles()+"");
                for (int i=0; i<mlist.get(position).getFiles().size(); i++){
                    Glide.with(mcontext).load(mlist.get(position).getFiles().get(i).getPath() + "").apply(new RequestOptions()
                            .placeholder(R.mipmap.banner).error(R.mipmap.banner)
                            .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
                    ).into(iv_geren_main_banner);
                }
            }
            tv_geren_main_open_all.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    tv_geren_main_open_all.setVisibility(View.GONE);
                    s_id = mlist.get(position).getId() + "";
                    postGetPLlistData(lv_xyf_jilu);
                }
            });
            tv_nearby_listview_item_name.setText("" + mlist.get(position).getNicename());
            tv_nearby_listview_item_distance.setText("" + mlist.get(position).getDistance() + " | " + mlist.get(position).getCreate_at());
            tv_nearby_listview_item_content.setText("" + mlist.get(position).getContent());
            tv_nearby_listview_item_look.setText("浏览" + mlist.get(position).getLook() + "次");
            tv_geren_main_dianzan.setText("" + mlist.get(position).getComment_count());
            tv_geren_main_pinglun.setText("" + mlist.get(position).getShare());
            Glide.with(mcontext).load(mlist.get(position).getHead_path() + "").apply(new RequestOptions()
                    .placeholder(R.mipmap.bd_circle_logo).error(R.mipmap.bd_circle_logo)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
            ).into(iv_nearby_item_icon);
        }
        return convertView;
    }

    /**
     * 网络请求
     */
    @SuppressLint("SetTextI18n")
    private void postZhiChiData(View v, int selected) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.square_zhichi_list_Url + access_token, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_zhichi", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        mlist_wallet = gson.fromJson(info.toString(), new TypeToken<List<User_Wallet>>(){}.getType());
                        CommonPopWindow.newBuilder()
                                .setView(R.layout.pop_square_detail_pay)
                                .setAnimationStyle(R.style.AnimUp)
                                .setBackgroundDrawable(new BitmapDrawable())
                                .setSize(0, 1200)
                                .setViewOnClickListener(new CommonPopWindow.ViewClickListener() {
                                    @Override
                                    public void getChildView(PopupWindow mPopupWindow, View view, int mLayoutResId) {
                                        GridView gv_pop_pay = view.findViewById(R.id.gv_pop_pay);
                                        Circle_ImageView civ_pop_square = view.findViewById(R.id.civ_pop_square);
                                        TextView tv_vip_zx_title = view.findViewById(R.id.tv_vip_zx_title);
                                        ImageView tv_vip_zx_price = view.findViewById(R.id.tv_vip_zx_price);
                                        Button btn_login = view.findViewById(R.id.btn_login);
                                        Glide.with(mcontext).load(mlist.get(selected).getHead_path() + "").apply(new RequestOptions()
                                                .placeholder(R.mipmap.bd_circle_logo).error(R.mipmap.bd_circle_logo)
                                                .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
                                        ).into(civ_pop_square);
                                        tv_vip_zx_title.setText("" + mlist.get(selected).getNicename());
//                                        if (user_informations.get(roomId).getIs_vip() == 1){
//                                            tv_vip_zx_price.setVisibility(View.VISIBLE);//是 会员
//                                        } else {
//                                            tv_vip_zx_price.setVisibility(View.INVISIBLE);
//                                        }
                                        gv_pop_pay.setVerticalSpacing(20);
                                        gv_pop_pay.setHorizontalSpacing(20);
                                        GV_Recharge_Item_Adapter adapter = new GV_Recharge_Item_Adapter(mcontext, mlist_wallet, 0);
                                        gv_pop_pay.setAdapter(adapter);
                                        gv_pop_pay.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                            @Override
                                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                                adapter.setSelect(position);
                                                adapter.notifyDataSetChanged();
                                                bd_money = mlist_wallet.get(position).getMoney();
                                                s_id = mlist_wallet.get(position).getId() + "";
                                            }
                                        });
                                        btn_login.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                mPopupWindow.dismiss();
                                                CommonPopWindow.newBuilder()
                                                        .setView(R.layout.pop_square_detail_zhichi)
                                                        .setAnimationStyle(R.style.AnimUp)
                                                        .setBackgroundDrawable(new BitmapDrawable())
                                                        .setSize(0, 600)
                                                        .setViewOnClickListener(new CommonPopWindow.ViewClickListener() {
                                                            @Override
                                                            public void getChildView(PopupWindow window, View view, int mLayoutResId) {
                                                                ImageView iv_pop_square_detail_cancle = view.findViewById(R.id.iv_pop_square_detail_cancle);
                                                                TextView tv_geren_fans_cancle = view.findViewById(R.id.tv_geren_fans_cancle);
                                                                TextView tv_geren_fans_cancle2 = view.findViewById(R.id.tv_geren_fans_cancle2);
                                                                iv_pop_square_detail_cancle.setOnClickListener(new View.OnClickListener() {
                                                                    @Override
                                                                    public void onClick(View v) {
                                                                        window.dismiss();
                                                                    }
                                                                });
                                                                tv_geren_fans_cancle.setText("" + bd_money.substring(0, bd_money.length()-3));
                                                                tv_geren_fans_cancle2.setText("果冻（需消耗" + bd_money.substring(0, bd_money.length()-3) + "布丁）");
                                                                Button btn_login1 = view.findViewById(R.id.btn_login);
                                                                btn_login1.setOnClickListener(new View.OnClickListener() {
                                                                    @Override
                                                                    public void onClick(View v) {
                                                                        window.dismiss();
                                                                        JSONObject object = new JSONObject();
                                                                        try {
                                                                            object.put("s_id", s_id);
                                                                            object.put("bd_money", bd_money);
                                                                            object.put("t_uid", mlist.get(selected).getUid());
                                                                            object.put("pay_psd", "");
                                                                        } catch (JSONException e) {
                                                                            e.printStackTrace();
                                                                        }
                                                                        postZhiChi_PayData(object, v, window);
                                                                    }
                                                                });
                                                            }
                                                        })
                                                        .setBackgroundDarkEnable(true)
                                                        .setBackgroundAlpha(0.7f)
                                                        .build(mcontext)
                                                        .showAsCenter(v);
                                            }
                                        });
                                    }
                                })
                                .setBackgroundDarkEnable(true)
                                .setOutsideTouchable(false)
                                .setBackgroundAlpha(0.7f)
                                .build(mcontext)
                                .showAsCenter(v);
                    } else {
                        ToolUtils.showToast(mcontext, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(mcontext, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(mcontext).add(request);
    }

    /**
     * 网络请求
     */
    @SuppressLint("SetTextI18n")
    private void postData(JSONObject object, TextView tv_geren_main_dianzan) {
        Log.d("square", object.toString());
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.square_dz_list_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONObject info = jsonObject.getJSONObject("info");
                        ToolUtils.showToast(mcontext, message);//点赞成功
                        tv_geren_main_dianzan.setText("" + info.optInt("support"));
                    } else {
                        ToolUtils.showToast(mcontext, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(mcontext, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(mcontext).add(request);
    }

    /**
     * 网络请求
     */
    private void postUserFansData(JSONObject object, ImageView iv_square_care) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.lt_edit_fans_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("dongtai_fans", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        ToolUtils.showToast(mcontext, message);
                        iv_square_care.setImageResource(R.mipmap.iv_ok_care);//关注成功
                    } else {
                        ToolUtils.showToast(mcontext, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(mcontext, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(mcontext).add(request);
    }

    /**
     * 网络请求
     */
    private void postZhiChi_PayData(JSONObject object, View v, PopupWindow mpopwindow) {
        Log.d("square", object.toString());
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, RequestConnect.square_zhichi_pay_Url + access_token, object, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        ToolUtils.showToast(mcontext, message);//打赏成功
                        mpopwindow.dismiss();
                    } else if (code == 300){
                        mpopwindow.dismiss();
                        //布丁币不足，请充值
                        CommonPopWindow.newBuilder()
                                .setView(R.layout.pop_geren_fans_cancle)
                                .setAnimationStyle(R.style.AnimUp)
                                .setBackgroundDrawable(new BitmapDrawable())
                                .setSize(0, 600)
                                .setViewOnClickListener(new CommonPopWindow.ViewClickListener() {
                                    @Override
                                    public void getChildView(PopupWindow mPopupWindow, View view, int mLayoutResId) {
                                        TextView tv_cancle = view.findViewById(R.id.tv_cancle);
                                        TextView tv_geren_fans_cancle1 = view.findViewById(R.id.tv_geren_fans_cancle);
                                        TextView img_guanbi = view.findViewById(R.id.img_guanbi);
                                        tv_geren_fans_cancle1.setText("余额不足，快去充值");
                                        tv_cancle.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                mPopupWindow.dismiss();
                                            }
                                        });
                                        img_guanbi.setText("充值");
                                        img_guanbi.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                mPopupWindow.dismiss();
                                                Intent intent = new Intent(mcontext, My_Wallet_Recharge_Activity.class);
                                                intent.putExtra("access_token", access_token);
                                                mcontext.startActivity(intent);
                                            }
                                        });
                                    }
                                })
                                .setBackgroundDarkEnable(true)
                                .setBackgroundAlpha(0.7f)
                                .build(mcontext)
                                .showAsCenter(v);
                    } else {
                        ToolUtils.showToast(mcontext, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(mcontext, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(mcontext).add(request);
    }

    /**
     * 网络请求-获取评论列表
     */
    private void postGetPLlistData(CustomListView listView) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.square_pinglun_Url + access_token + "&s_id=" + s_id + "&s_com_id=0&page=1&limit=2", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("square_pl", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONArray info = jsonObject.getJSONArray("info");
                        List<User_Limit> user_limit = gson.fromJson(info.toString(), new TypeToken<List<User_Limit>>(){}.getType());
                        listView.setAdapter(new Photo_Album_Adapter(mcontext, null, null, user_limit, 3));
                        listView.setOnTouchListener(new View.OnTouchListener() {
                            @Override
                            public boolean onTouch(View v, MotionEvent event) {
                                int action = event.getAction();
                                switch (action) {
                                    case MotionEvent.ACTION_DOWN:
                                        // Disallow ScrollView to intercept touch events.
                                        v.getParent().requestDisallowInterceptTouchEvent(true);//当触摸按下时关闭主页面滑动
                                        break;
                                    case MotionEvent.ACTION_UP:
                                        // Allow ScrollView to intercept touch events.
                                        v.getParent().requestDisallowInterceptTouchEvent(false);
                                        break;
                                }
                                // Handle ListView touch events.
                                v.onTouchEvent(event);
                                return true;
                            }
                        });
                        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                ToolUtils.showToast(mcontext, "点击了" + position);
                            }
                        });
                    } else {
                        ToolUtils.showToast(mcontext, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(mcontext, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(mcontext).add(request);
    }
}